<td class="align-top width-400">        
<section class="cell-light">
    <header>
        <h2><?php echo ( $user ) ? $user->displayname() : 'Create New User'; ?></h2>
        <?php $session->display_messages('user'); ?>
    </header>
<form class="edit-form group" action="<?php $Controller->page_url(); ?>" method="post">
    <input type="hidden" value="<?php echo ( $user ) ? $user->attr('user_id') : '0'; ?>" name="user_id" />
    <?php
    
    $form_array = array(
        'First Name*' => 'firstname',
        'Last Name*' => 'lastname',
        'Phone' => 'phone',
        'Email' => 'email',
        'Rural Route #' => 'rr',
        'Box #' => 'box',
        'Apt #' => 'apt',
        'Street #' => 'street_address',
        'Street' => 'street',
        'City*' => 'city',
        'Province*' => 'province',
        'Postal Code*' => 'postal_code',
        'Country*' => 'country',
        'City*' => 'city',
    );
    ?>
    
    <label><span>Added:</span>
    <input type="text" disabled value="<?php echo ( $user ) ? date("F j Y", strtotime($user->user_datestamp)) : date("F j Y"); ?>" name="user_datestamp" />
    <span class="show-tool-tip" title="The date this user was officially added. It cannot be changed.">?</span>
    </label>
                                
    <?php
    
    //
    //  This is a bit nasty looking. However, it just loops through the form array, and switches out for types.
    //  $provinces is defined in data.php
    //
    foreach($form_array as $label => $input ) :
    ?>
    <label><span><?php echo $label ?></span>
    <?php
        switch ($input) {
            case 'province': ?>
                    <select name="province">
                        <?
                        foreach ( $provinces as $key => $value ) {
                            if ( $user && strtolower($user->province) == strtolower($key) ) {
                                echo '<option value="'.$key.'" selected >'.$value.'</option>';
                            } elseif ( strtolower($key) == 'bc' && !isset($user->province) ) {
                                echo '<option value="'.$key.'" selected >'.$value.'</option>';
                            } else {
                                echo '<option value="'.$key.'">'.ucwords($value).'</option>';
                            }
                        } ?>
                    </select> 
                    <span class="show-tool-tip" title="Required: The province in which this user would like their subscription sent.">?</span>
                <?php
                break;
                
           case 'country' :   ?>
                    <select name="country">
                        <option value="Canada" default>Canada</option>
                    </select>
                    <span class="show-tool-tip" title="Required: The country in which this user would like their subscription sent.">?</span>

                <?php 
                break;
           case 'postal_code' :
                $value = ( $user ) ? $user->get_attr($input) : '';
                ?>
                    <input type="text" value="<?php echo strtoupper( $value )  ?>" name="<?php echo $input; ?>" />
                    <span class="show-tool-tip" title="Please fill in as accurately as you can.">?</span>
                <?php 
                break;
                     
           default: ?>
                   <input type="text" value="<?php echo ( $user ) ? $user->get_attr($input) : ''; ?>" name="<?php echo $input; ?>" />
                   <span class="show-tool-tip" title="Please fill in as accurately as you can.">?</span>
            <?php     
                break;
                
        }
    ?>
    
    </label>
    <?php endforeach; ?>
    <hr>
    <div class="group">
        <input type="hidden" name="action" value="update_user" />
        <input type="hidden" name="user_id" value="<?php echo ( $user ) ? $user->get_attr('user_id') : ''; ?>" />
        <input class="right primary-button skin-gradient" type="submit" name="update_user_redirect" value="Save & Close" />
        <input class="right primary-button skin-gradient" type="submit" name="update_user" value="Save" />
        <a class="right text-button" href="<?php echo $Controller->page_url('subscriptions'); ?>" title="cancel new subscription">Cancel</a>
        <a class="show-tool-tip right text-button" href="#" title="Fill in these fields as best you can. Fields like phone number and email aren't crucial, but there are benefits. Be sure you input the correct address, as this is what we use for the mailing labels!">Help</a>
    </div>
       
</form>
</section>
</td>





<?php if ($template_type == 'new' || $template_type == 'invalid' ) : 
    //
    // NEW SUB FROM EXISTING, UNSUBSCRIBED USER.
    //
    $found_users = User::find_by_unsubscribed();
    if ($found_users) :
    ?>
    
<?php endif; // end found subs 
      endif; // end new ?>
      
